package com.nikitova.craps3d.controller 
{
	import com.nikitova.craps3d.model.ScreenProxy;
	import com.nikitova.craps3d.view.CameraMediator;
	import com.nikitova.craps3d.view.GameDataPreloaderMediator;
	import com.nikitova.craps3d.view.GameView3DMediator;
	import com.nikitova.craps3d.view.TableBorderMediator;
	import com.nikitova.craps3d.view.TableClothMediator;
	import com.nikitova.craps3d.view.components.GameDataPreloader;
	import com.nikitova.craps3d.view.components.game3d.GameView3D;

	import org.puremvc.as3.multicore.interfaces.*;
	import org.puremvc.as3.multicore.patterns.command.*;

	import flash.display.*;

	/**
	 * @author schranz
	 */
	public class ViewPrepCommand extends SimpleCommand
	{
		private var _mainContainer			: DisplayObjectContainer;
		private var _screenProxy			: ScreenProxy;
		
		override public function execute( note:INotification ) :void
		{
			// Main container
			_mainContainer = DisplayObjectContainer(note.getBody());
			
			_screenProxy = facade.retrieveProxy(ScreenProxy.NAME) as ScreenProxy;
			
			createGameDataPreloader();
			createGameView3D();
		}		
		
		private function createGameDataPreloader():void
		{
			var gameDataPreloader				: GameDataPreloader					= new GameDataPreloader();
			var gameDataPreloaderMediator		: GameDataPreloaderMediator			= new GameDataPreloaderMediator(gameDataPreloader);
			facade.registerMediator( gameDataPreloaderMediator );	
			_screenProxy.guiContainer.addChild( gameDataPreloader );
		}
		
		private function createGameView3D():void
		{
			//Register game view 3D mediator
			var gameView3D						: GameView3D 						= new GameView3D(_mainContainer.stage.stageWidth,_mainContainer.stage.stageHeight);
		 	var gameView3DMediator				: GameView3DMediator				= new GameView3DMediator(gameView3D);
			facade.registerMediator( gameView3DMediator );	
			_screenProxy.game3DContainer.addChild(gameView3D);
			
			//Register camera mediator
			var cameraMediator				: CameraMediator				= new CameraMediator(gameView3DMediator.camera);
			cameraMediator.stage = _screenProxy.stage;
			facade.registerMediator( cameraMediator );
			
			//Register table cloth mediator
			var tableClothMediator					: TableClothMediator 					= new TableClothMediator(null);
			facade.registerMediator(tableClothMediator);
			
			//Register table border mediator
			var tableBorderhMediator					: TableBorderMediator 				= new TableBorderMediator(null);
			facade.registerMediator(tableBorderhMediator);
			
		}
	}
}